<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title>应收账单</title>
    <link rel="stylesheet" href="../../../public/dist/css/layui.css">
    <link rel="stylesheet" href="../../../css/departmentbase.css">
    <link rel="stylesheet" href="../../../public/font/iconfont.css">
</head>

<body>
    <!-- 查询 -->
    <div class="select">
        <div class="select-left">
            <div class="select-item">
                <div class="select-item-text" style="width: 90px">
                    账单单号
                </div>
                <input type="text" class="layui-input select-item-input" id="a" search-type="a">
            </div>
            <div class="select-item" style="margin-left: 20px;">
                <div class="select-item-text">
                    供应商名称
                </div>

                <select name="" id="b" class="select-item-select2">
                    <option value="">--请选择--</option>
                </select>
            </div>
        </div>

        <div class="select-right">
            <div class="select-btn  search" lay-event="search">
                查询
            </div>
            <div class="select-btn reset " lay-event="reset">
                清除
            </div>
        </div>
    </div>

    <div class="common-padding">
        <table class="layui-hide" id="gylMaterialmaintain" lay-filter="gylMaterialmaintain"></table>
    </div>
</body>
<script src="../../../public/dist/layui.js" charset="utf-8"></script>
<script src="../../../js/common/jquery.min.js"></script>
<script src="../../../js/common/api.js"></script>

</html>

<!-- 头部 -->
<script type="text/html" id="toolbarinter">
    <div class="layui-btn-container ">
        <button class="layui-btn  layui-btn-sm colors layui-bg-black" lay-event="pay">确认收款</button>
        <button class="layui-btn  layui-btn-sm colors  layui-bg-black" lay-event="delete">删除</button>
    </div>
</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">查看</a>
</script>

<script>
    layui.use(["table", "laydate", "layer", "util", "form"], function() {
        var $ = layui.jquery,
            util = layui.util,
            layer = layui.layer,
            form = layui.form,
            laydate = layui.laydate,
            table = layui.table;

        //供应商
        noAjax("coa/getSuppliersList", {}, "get").done(function(resp) {
            $.each(resp.ipage.records, function(v, item) {
                $("#b").append('<option  value="' + item.fullName + '">' + item.fullName + '</option>')
            })
            form.render('select');
            return
        }).fail(function(err) {
            console.log(err)
        });


        //监听头部监听
        table.on('toolbar(gylMaterialmaintain)', function(obj) {
            var checkStatus = table.checkStatus(obj.config.id),
                data = checkStatus.data; //获取选中的数据
            switch (obj.event) {
                case 'pay':
                var list = data[0];
                    if (list.transStatus == '40') {
                        var obj = {};
                        layer.prompt({
                            formType: 2,
                            value: '',
                            title: '请输入支付方式',
                            area: ['200px', '50px'] //自定义文本域宽高
                        }, function (value,index) {
                            //得到value 
                            obj.isLoan = value;
                            layer.close(index);
                            console.log(list.id)
                            obj.id = list.id;
                            obj.repaymentSum = 11;
                            console.log(obj)
                            handleAjax("coa/procurementOrderPay", obj, "POST").done(function(res){
                                console.log('成功')
                            })
                            tableIns.reload()
                                layer.msg('操作成功')
                        });
                    } else {
                        layer.msg('操作失败')
                    }
                    break;
                case 'delete':
                    if (data.length === 0) {
                        layer.msg('请选择一行');
                    } else {

                        noAjax("coa/delAccount", {
                            id: data[0].id
                        }, "POST").done(function(resp) {
                            layer.msg('操作成功', {
                                icon: 1,
                                time: 1000
                            });
                            setTimeout(function() {
                                tableIns.reload({
                                    where: {
                                        billtype: 2
                                    },
                                    page: {
                                        curr: 1, //重新从第 1 页开始
                                        layout: ['prev', 'page', 'next', 'skip', 'count']
                                    },
                                })
                            }, 1500)
                            return
                        }).fail(function(err) {
                            console.log(err)
                        });
                    }
                    break;
            };
        });



        var tableIns = table.render({
            elem: "#gylMaterialmaintain",
            url: base + "coa/getOrderList",
            method: "GET",
            where: {
                transStatus: '30',
                transType: "销售订单"
            },
            headers: {
                Authorization: "Bearer" + " " + sessions
            },
            request: {
                pageName: "currentPage",
                limitName: "pageSize"
            },
            toolbar: "#toolbarinter",
            limits: [10, 20],
            parseData: function (res) {
                //res 即为原始返回的数据
                console.log(res)
                return {
                    code: res.code, //解析接口状态
                    msg: res.message, //解析提示文本
                    totalNum: res.pageBean.totalNum, //解析数据长度
                    lists: res.pageBean.lists //解析数据列表
                };
            },
            response: {
                statusName: "code", //数据状态的字段名称，默认：code
                statusCode: 10000, //成功的状态码，默认：0
                msgName: "message", //状态信息的字段名称，默认：msg
                countName: "totalNum", //数据总数的字段名称，默认：count
                dataName: "lists" //数据列表的字段名称，默认：data
            },

            cellMinWidth: 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            page: {
                //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ["prev", "page", "next", "skip", "count"], //自定义分页布局
                //,curr: 5 //设定初始在第 5 页
                groups: 5, //只显示 1 个连续页码
                first: true, //不显示首页
                last: true, //不显示尾页
                prev: "上一页",
                next: "下一页",
                theme: "#c81623"
            },
            // height: 'full-20',//满高
            cols: [
                [{
                    type: 'checkbox',
                    fixed: "left",
                }, {
                    field: "transNo",
                    title: "采购单号",
                    minWidth: 110,
                    align: "center"
                }, {
                    field: "transDate",
                    title: "采购日期",
                    minWidth: 120,
                    sort: true,
                    align: "center",
                    templet: function (d) {
                        var numv = null;
                        if (d.transDate == "" || d.transDate == null) {
                            numv = " ";
                        } else {
                            numv = d.transDate = layui.util.toDateString(
                                d.transDate,
                                "yyyy-MM-dd"
                            );
                        }
                        return numv;
                    }
                },{
                    field: "transStatus",
                    title: "订单状态",
                    minWidth: 200,
                    sort: true,
                    align: "center",
                    templet: function (d) {
                        var numv = null;
                        if (d.transStatus == "10") {
                            numv = "采购订单提交待审核";
                        }
                        else if (d.transStatus == "20") {
                            numv = "采购订单审核通过";
                        }
                        else if (d.transStatus == "15") {
                            numv = "采购订单审核不通过";
                        }
                        else if (d.transStatus == "30") {
                            numv = "销售订单待收款";
                        }
                        else if (d.transStatus == "35") {
                            numv = "销售订单审核不通过";
                        }
                        else if (d.transStatus == "40") {
                            numv = "采购订单付款完成";
                        }
                        else if (d.transStatus == "50") {
                            numv = "销售订单发货";
                        }
                        else if (d.transStatus == "60") {
                            numv = "采购订单收货";
                        }
                        else if (d.transStatus == "70") {
                            numv = "采购订单申请退货";
                        }
                        else if (d.transStatus == "80") {
                            numv = "采购方待退货";
                        }
                        else if (d.transStatus == "85") {
                            numv = "销售方不同意退货";
                        }
                        else if (d.transStatus == "90") {
                            numv = "采购退货";
                        }
                        else if (d.transStatus == "100") {
                            numv = "销售收获并退款";
                        }
                        return numv;
                    }
                }, {
                    field: "customerVendorName",
                    title: "供应商名称",
                    minWidth: 100,
                    sort: true,
                    align: "center"
                }, {
                    field: "salesman",
                    title: "采购员名称",
                    minWidth: 100,
                    sort: true,
                    align: "center"
                }, {
                    field: "estShipDate	",
                    title: "预交日",
                    minWidth: 120,
                    sort: true,
                    align: "center",
                    templet: function (d) {
                        var numv = null;
                        if (d.estShipDate == "" || d.estShipDate == null) {
                            numv = " ";
                        } else {
                            numv = d.estShipDate = layui.util.toDateString(
                                d.estShipDate,
                                "yyyy-MM-dd"
                            );
                        }
                        return numv;
                    }
                }, {
                    field: "remark",
                    title: "备注",
                    minWidth: 100,
                    align: "center"
                }, {
                    field: "userName",
                    title: "制表人名称",
                    minWidth: 100,
                    align: "center"
                }, {
                    field: "editTime",
                    title: "单身数据",
                    minWidth: 80,
                    align: "center",
                    toolbar: '#barDemo'
                }, {
                    field: "editTime",
                    title: "修改时间",
                    minWidth: 130,
                    sort: true,
                    align: "center",
                    fixed: 'right',
                    templet: function (d) {
                        var numv = null;
                        if (d.editTime == "" || d.editTime == null) {
                            numv = " ";
                        } else {
                            numv = d.editTime = layui.util.toDateString(
                                d.editTime,
                                "yyyy-MM-dd"
                            );
                        }
                        return numv;
                    }
                },
                ]
            ]
        });

        // var tableIns = table.render({
        //     elem: "#gylMaterialmaintain",
        //     url: base + "coa/getAccountList",
        //     method: "GET",
        //     where: {
        //         billtype: 2
        //     },
        //     headers: {
        //         Authorization: "Bearer" + " " + sessions
        //     },
        //     request: {
        //         pageName: "currentPage",
        //         limitName: "pageSize"
        //     },
        //     toolbar: "#toolbarinter",
        //     limits: [10, 20],
        //     parseData: function(res) {
        //         //res 即为原始返回的数据
        //         console.log(res);
        //         return {
        //             code: res.code, //解析接口状态
        //             msg: res.message, //解析提示文本
        //             totalNum: res.pageBean.totalNum, //解析数据长度
        //             lists: res.pageBean.lists //解析数据列表
        //         };
        //     },
        //     response: {
        //         statusName: "code", //数据状态的字段名称，默认：code
        //         statusCode: 10000, //成功的状态码，默认：0
        //         msgName: "message", //状态信息的字段名称，默认：msg
        //         countName: "totalNum", //数据总数的字段名称，默认：count
        //         dataName: "lists" //数据列表的字段名称，默认：data
        //     },

        //     cellMinWidth: 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
        //     page: {
        //         //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
        //         layout: ["prev", "page", "next", "skip", "count"], //自定义分页布局
        //         //,curr: 5 //设定初始在第 5 页
        //         groups: 5, //只显示 1 个连续页码
        //         first: true, //不显示首页
        //         last: true, //不显示尾页
        //         prev: "上一页",
        //         next: "下一页",
        //         theme: "#c81623"
        //     },
        //     // height: 'full-20',//满高
        //     cols: [
        //         [{
        //             type: 'checkbox',
        //             fixed: "left"
        //         }, {
        //             field: "billstime",
        //             title: "应付日期",
        //             minWidth: 120,
        //             sort: true,
        //             align: "center",
        //             templet: function(d) {
        //                 var numv = null;
        //                 if (d.billstime == "" || d.billstime == null) {
        //                     numv = " ";
        //                 } else {
        //                     numv = d.billstime = layui.util.toDateString(
        //                         d.billstime,
        //                         "yyyy-MM-dd"
        //                     );
        //                 }
        //                 return numv;
        //             }
        //         }, {
        //             field: "billcode",
        //             title: "应付单号",
        //             minWidth: 110,
        //             align: "center"
        //         }, {
        //             field: "csname",
        //             title: "供应商名称",
        //             minWidth: 140,
        //             align: "center"
        //         }, {
        //             field: "closed",
        //             title: "是否关闭",
        //             minWidth: 110,
        //             sort: true,
        //             align: "center"
        //         }, {
        //             field: "paymentterms",
        //             title: "付款条件",
        //             minWidth: 100,
        //             align: "center"
        //         }, {
        //             field: "listername",
        //             title: "制表人名称",
        //             minWidth: 100,
        //             align: "center"
        //         }, {
        //             field: "approve",
        //             title: "批准",
        //             minWidth: 100,
        //             align: "center"
        //         }, {
        //             field: "approver",
        //             title: "审批人名称",
        //             minWidth: 100,
        //             align: "center"
        //         }, {
        //             field: "invoicetime",
        //             title: "发票日期",
        //             minWidth: 120,
        //             sort: true,
        //             align: "center",
        //             templet: function(d) {
        //                 var numv = null;
        //                 if (d.invoicetime == "" || d.invoicetime == null) {
        //                     numv = " ";
        //                 } else {
        //                     numv = d.invoicetime = layui.util.toDateString(
        //                         d.invoicetime,
        //                         "yyyy-MM-dd"
        //                     );
        //                 }
        //                 return numv;
        //             }
        //         }, {
        //             field: "editTime",
        //             title: "账单单身",
        //             minWidth: 80,
        //             align: "center",
        //             toolbar: '#barDemo'
        //         }, ]
        //     ]
        // });

        /*查询*/
        $(".search").click(function() {
            if ($("#a").val() == "" && $("#b").val() == "") {
                layer.msg("请输入查询条件！", {
                    time: 1000,
                    offset: "t"
                });
                return;
            }

            var datelist = {
                billcode: $("#a").val(),
                csname: $("#b").val().trim(),
                billtype: 2
            };
            tableIns.reload({
                where: datelist,
                request: {
                    pageName: "currentPage", //页码的参数名称，默认：page
                    limitName: "pageSize" //每页数据量的参数名，默认：limit
                },
                page: {
                    curr: 1, //重新从第 1 页开始
                    layout: ["prev", "page", "next", "skip", "count"]
                }
            });
        });

        /*重置*/
        $(".reset").click(function() {
            $("#a").val("");
            $("#b").val("");
            tableIns.reload({
                where: {
                    billtype: 2
                },
                page: {
                    curr: 1, //重新从第 1 页开始
                    layout: ["prev", "page", "next", "skip", "count"]
                }
            });
        });

        //查看
        var rys = null;
        table.on('tool(gylMaterialmaintain)', function(obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            if (layEvent === 'edit') { //查看
                layer.open({
                    type: 1,
                    title: "账单单身",
                    shadeClose: true, //是否点击遮罩关闭
                    anim: 5, //弹出动画
                    scrollbar: false, //窗口外滚动条是否出现
                    skin: 'layui-layer-rim', //加上边框
                    area: ['860px', '300px'], //宽高
                    content: '<div id="sssd"  style="margin:10px;"></div>',
                    success: function(layero, index) {
                        console.log(data.coProductBillList)
                        $.each(data.coProductBillList, function(v, its) {
                            rys = '<tr>' +
                                '<td>' + its.billcode + '</td>' +
                                '<td>' + its.productname + '</td>' +
                                '<td>' + its.productcode + '</td>' +
                                '<td>' + its.specifications + '</td>' +
                                '<td>' + its.num + '</td>' +
                                '<td>' + its.unit + '</td>' +
                                '<td>' + its.taxrate + '</td>' +
                                '<td>' + its.unitprice + '</td>' +
                                '<td>' + its.taxprice + '</td>' +
                                '<td>' + its.notmoney + '</td>' +
                                '<td>' + its.money + '</td>' +
                                '<td>' + its.amountmoney + '</td>' +
                                '</tr>'
                        })
                        console.log(rys)

                        $("#sssd").html('<table lay-filter="parse-table-demo">' +
                            '<thead> <tr>' +
                            '<th lay-data="{field:\'df\', minWidth:100}">源单据号</th>' +
                            '<th lay-data="{field:\'username\', minWidth:100}">物料名称</th>' +
                            '<th lay-data="{field:\'d\', minWidth:100}">产品代号</th>' +
                            '<th lay-data="{field:\'userwname\', minWidth:100}">物料规格</th>' +
                            '<th lay-data="{field:\'w\', minWidth:100}">应付数量</th>' +
                            '<th lay-data="{field:\'e\', minWidth:100}">单位</th>' +
                            '<th lay-data="{field:\'r\', minWidth:100}">税率</th>' +
                            '<th lay-data="{field:\'p\', minWidth:100}">单价</th>' +
                            '<th lay-data="{field:\'t\', minWidth:100}">含税单价</th>' +
                            '<th lay-data="{field:\'y\', minWidth:100}">不含税金额</th>' +
                            '<th lay-data="{field:\'u\', minWidth:100}">含税金额</th>' +
                            '<th lay-data="{field:\'i\', minWidth:100}">应付金额</th>' +
                            '</tr> ' +
                            '</thead>' +
                            '<tbody>' + rys + '</tbody>' +
                            '</table> ')
                        table.init('parse-table-demo', { //转化静态表格
                        });
                    }
                });
            }
        });


    });
</script>